home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Just Call Me Internet
/
Just Call Me Internet.iso
/
prog
/
atari
/
c
/
mail110
/
log.c
< prev
next >
Wrap
C/C++ Source or Header
|
1994-02-14
|
1KB
|
76 lines
/*==============================================
//
// log.c
//
// log outgoing mail
//
//==============================================
*/
#include <stdio.h>
#include "mailer.h"
#define FROM "From:"
int append_to_log (char *txt)
{
FILE *fplog, *fptxt;
int res = 0;
char *p, *buf;
fprintf (stderr, "appending %s to %s\n", txt, log);
if ((buf = (char *)malloc (1024)) == NULL)
{
fprintf (stderr, "log: out of memory\n");
return 0;
}
if (!*log)
{
fprintf (stderr, "log: no log file specified\n");
return 0;
}
if (access (log, 0) != 0)
{
fplog = fopen (log, "w");
if (fplog == NULL)
perror ("log: failed to create log file");
}
else
{
fplog = fopen (log, "a");
if (fplog == NULL)
perror ("log: failed to open log file");
}
if (fplog != NULL)
{
fptxt = fopen (txt, "r");
if (fptxt == NULL)
perror ("log: failed to open txt file");
else
{
while (fgets (buf, 1024, fptxt) != NULL)
{
if (!strncmp (buf, FROM, strlen (FROM)))
{
p=strchr (buf, ':');
*p = ' ';
fprintf (fplog, "%s", buf);
break;
}
}
rewind (fptxt);
while (fgets (buf, 1024, fptxt) != NULL)
fputs (buf, fplog);
fprintf (fplog, "\n\n");
fclose (fplog);
fclose (fptxt);
res = 1;
}
}
free (buf);
return res;
}